package com.qf.springcloud.order.controller;

import com.qf.springcloud.order.pojo.Order;
import com.qf.springcloud.order.pojo.OrderItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/orders")
public class OrderController {

    private RestTemplate restTemplate;

    @Autowired
    public void setRestTemplate(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @GetMapping("/order/{id}")
    public Order getOrderById(@PathVariable Integer id){

        Order order=new Order();
        order.setId(id);
        order.setAddress("狮驼岭2楼");
        //通过 eureka 获取地址,参数 1 程序在 eureka 中的名字
        OrderItem orderItem = restTemplate.getForObject("http://04ITEMPROVIDER-EUREKA/items/item/" + id, OrderItem.class);
        order.setOrderItem(orderItem);
        return order;

    }
}
